# reshape
# https://www.bilibili.com/video/BV19T4y127Z2?p=6&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
import numpy as np
print("reshape")

a = np.array([("Germany", "France", "Hungary", "China"), ("Berlin", "Paris", "Budapest", "Beijing")])
print(a)
print(a.shape)
#a.shape()这样写是不对的
#print(a.shape())

# 讲多维数组变成一维数组
ar = a.ravel()
print(ar)

# 转置
print("# a.T ##############################")
print(a.T)
print(a.T.ravel())

# reshape
print("# reshape ##########################")
print(a)
a.reshape(4, 2)
print(a)
areshape = a.reshape(4, 2)
print(areshape)

#
print("# ##################################")
print(np.arange(15).reshape(3, 5))
print(np.arange(15).reshape(5, 3))

#
print("# ##################################")
c = np.array(["China", "USA", "UK", "Italy", "Russia", "Germany"])
print(c)
# -1 表示要让numpy把行数算出来
# 可以分配开的情况
print(c.reshape(-1, 3))
print(c.reshape(3, -1))
# 如果不能分配开呢？ 答：会报错！
# print(c.reshape(4, -1))